package com.wing.common.services;

import java.util.Properties;

import javax.servlet.ServletConfig;
import javax.servlet.ServletContext;

public abstract class Service {
	  /**
     ** Constructs the service.
     **/
    protected Service () {

    }

    /**
     ** Initializes the service using the servlet configuration
     ** and the service properties.
     **
     ** @param   aConfig
     **          the servlet configuration
     ** @param   aProperties
     **          the service properties
     **
     ** @throws   Exception
     **           if the initialization fails
     **/

    protected void init (ServletConfig aConfig,
                         Properties aProperties) throws Exception
    {
        if(aConfig != null)
        {
            init (aConfig.getServletContext (), aProperties);
        }
        else
        {
            init (aProperties);
        }

    }
    
    protected void init (ServletConfig aConfig) throws Exception
	{
	
	}

    /**
     ** Initializes the service using the servlet context
     ** and the service properties.
     **
     ** @param   aContext
     **          the servlet context
     ** @param   aProperties
     **          the service properties
     **
     ** @throws   Exception
     **           if the initialization fails
     **/

    protected void init (ServletContext aContext,
                         Properties aProperties) throws Exception
    {
        init (aProperties);
    }

    /**
     ** Initializes the service using the service properties.
     **
     ** @param   aProperties
     **          the service properties
     **
     ** @throws   Exception
     **           if the initialization fails
     **/

    protected void init (Properties aProperties) throws Exception
    {
    }

    /**
     * This methods can be used to setup things after the services has 
     * been initialized via init.
     * 
     * @throws Exception
     *         if the postInit fails for any reason
     **/
    protected void postInit(ServletConfig aConfig) throws Exception 
    {
        postInit();
    }

    /**
     * This methods can be used to setup things after the services has 
     * been initialized via init.
     * 
     * @throws Exception
     *         if the postInit fails for any reason
     **/
    protected void postInit() throws Exception 
    {
    }

    /**
     ** Destroys the services. This method allows the service
     ** to cleanup any resources.
     **
     ** @param   aConfig
     **          the servlet configuration
     **
     ** @throws   Exception
     **           if the destruction fails
     **/
    protected void destroy (ServletConfig aConfig) throws Exception
    {
        destroy();
    }

    /**
     ** Destroys the services. This method allows the service
     ** to cleanup any resources.
     **
     ** @throws   Exception
     **           if the destruction fails
     **/
    protected void destroy () throws Exception
    {
    }
}
